import { fetchGoodList } from '@/api'
import deepCopy from '@/utils/copy'


export default {
    namespaced: true,
    state: {
        cache: {}
    },
    mutations: {
        updateCache(state, payload) {
            const { idx, list } = payload
            state.cache[idx] = list
            state.cache = deepCopy(state.cache)
        }
    },
    actions: {
        getList(store, payload) {
            const { idx, cate } = payload
            fetchGoodList({ cate }).then(res => {
                store.commit('updateCache', { idx, list: res.data.list })
            })
        }
    }
}